﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Model;
using DAL;
namespace Demo
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            StudentDAL studentDAL = new StudentDAL();
            List<Student> lstStudent = studentDAL.GetStudentsFromMock();

           //完成用户信息和图表要求的数据格式一一对应
            List<GraphData> lstGraphData = new List<GraphData>();
            for (int i = 0; i < lstStudent.Count; i++)
            {                
                GraphData graphData = new GraphData();
                graphData.name = lstStudent[i].StuName ;
                graphData.value = lstStudent[i].Score .ToString();
                lstGraphData.Add(graphData);
            }
            string json = JsonConvert.SerializeObject(lstGraphData);
            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}